package uwosh.cs342.project1;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class MySQLiteHelper extends SQLiteOpenHelper {

	public static final String TABLE_C = "contacts";
	public static final String C_ID = "_id";
	public static final String C_FIRST = "contactFirstName";
	public static final String C_MID = "contactMiddleName";
	public static final String C_LAST = "contactLastName";
	public static final String C_CELL = "contactCellPhone";
	public static final String C_HOME = "contactHomePhone";
	public static final String C_ALT = "contactAltPhone";
	public static final String C_ADDRESS = "contactAddress";
	public static final String C_BDAY = "contactBirthday";
	public static final String C_EMAIL = "contactEmail";
	public static final String C_COMMENT = "contactComments";
	public static final String C_GROUP = "contactGroup";

	public static final String TABLE_G = "groups";
	public static final String G_NAME = "name";

	private static final String DATABASE_NAME = "commments.db";
	private static final int DATABASE_VERSION = 1;

	// Database creation sql statement
	private static final String DATABASE_CREATE = "create table " + TABLE_C
			+ "( " + C_ID + " integer primary key autoincrement, " + C_FIRST
			+ " text, " + C_MID + " text, " + C_LAST + " text, " + C_CELL + " text, "
			+ C_HOME + " text, " + C_ALT + " text, " + C_ADDRESS + " text, " + C_BDAY
			+ " text, " + C_EMAIL + " text, " + C_COMMENT + " text, " + C_GROUP + " text);";

	private static final String GROUP_CREATE = "create table \"" + TABLE_G + "\"( "
			+ C_ID + " integer primary key autoincrement, " + G_NAME + " text);";

	public MySQLiteHelper(Context context) {
		super(context, DATABASE_NAME, null, DATABASE_VERSION);
	}

	@Override
	public void onCreate(SQLiteDatabase database) {
		database.execSQL(DATABASE_CREATE);
		database.execSQL(GROUP_CREATE);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		Log.w(MySQLiteHelper.class.getName(),
				"Upgrading database from version " + oldVersion + " to "
						+ newVersion + ", which will destroy all old data");
		db.execSQL("DROP TABLE IF EXISTS " + TABLE_C);
		db.execSQL("DROP TABLE IF EXISTS " + "\""+TABLE_G+"\"");
		onCreate(db);
	}

}